package service.applycheck.impl;

import java.util.List;

import service.applycheck.ApplyUserService;
import dao.security.UsrUserRoleDao;
import exception.Exceptions;
import model.security.UsrUserRole;

public class ApplyUserServiceImpl implements ApplyUserService{
	private UsrUserRoleDao usrUserRoleDao;

	/*@Override
	public UsrUserRole getFPUsrUserRole() {
		return this.usrUserRoleDao.findOne("roleid", 5);
	}*/

	public UsrUserRoleDao getUsrUserRoleDao() {
		return usrUserRoleDao;
	}

	public void setUsrUserRoleDao(UsrUserRoleDao usrUserRoleDao) {
		this.usrUserRoleDao = usrUserRoleDao;
	}

	@Override
	public UsrUserRole getOneByUserRoleId(Integer roleid) throws Exceptions {
		List<UsrUserRole> list = this.usrUserRoleDao.findList("roleid", roleid);
		if(list == null){
			throw new Exceptions("请检查是否已经设定该操作人员!");
		}
		return list.get(0);
	}

	@Override
	public List<UsrUserRole> getListByRoleId(Integer roleid) {
		return this.usrUserRoleDao.findList("roleid", roleid);
	}

	@Override
	public List<?> getUserByRoleId(Integer roleid) {
		String select = "new vo.UserBean(p.userid, p.useraccount)";
		String from = "UsrUserRole as u , UsrUser as p where u.usrUser.userid = p.userid and u.usrRole.roleid = " + roleid;
		return this.usrUserRoleDao.findQuery(select, from);
	}

	@Override
	public boolean isExamial(Long id) {
		UsrUserRole uu = this.usrUserRoleDao.findByOne("usrUser.userid = " + id + " and usrRole.roleid = 6");
		if(uu != null){
			return true;
		}
		return false;
	}
	
	@Override
	public boolean isAccept(Long id) {
		UsrUserRole uu = this.usrUserRoleDao.findByOne("usrUser.userid = " + id + " and usrRole.roleid = 13");
		if(uu != null){
			return true;
		}
		return false;
	}
	

}
